import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/1 13:02
 * @description map计数 + 滑动窗口
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int minimumCardPickup(int[] cards) {
        int n = cards.length;
        Map<Integer, Integer> map = new HashMap<>();
        int ans = Integer.MAX_VALUE;
        for (int l = 0, r = 0; r < n; r++) {
            map.put(cards[r], map.getOrDefault(cards[r], 0) + 1);
            while (map.get(cards[r]) > 1) {
                map.put(cards[l], map.get(cards[l]) - 1);
                ans = Math.min(ans, r - l + 1);
                l++;
            }
        }
        return  ans == Integer.MAX_VALUE ? -1 : ans;
    }
}
